#include "GLWindow.h"
#include "GLTestApplication.h"
using namespace OpenGLWrapper;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR strCmdLine, int nCmdShow)
{
	GLWindow window(hInstance, 900, 600, 32, false);

	GLTestApplication* gameApplicaion = new GLTestApplication();
	gameApplicaion->TestLeastSquares();

	window.SetGLApplication(gameApplicaion);
	gameApplicaion->Init();
	
	LARGE_INTEGER time1, time2, freq;
	QueryPerformanceFrequency(&freq);
	QueryPerformanceCounter(&time1);
	float elapsedTime = 0;
	while (window.IsRunning())
	{
		QueryPerformanceCounter(&time1);

		window.ProcessEvents();		
		gameApplicaion->Prepare(elapsedTime);
		gameApplicaion->Render();
		window.SwapBuffers();

		QueryPerformanceCounter(&time2);
		elapsedTime = float(time2.QuadPart - time1.QuadPart) / float(freq.QuadPart);
	}

	gameApplicaion->Shutdown();
	window.Destroy();

	delete gameApplicaion;

	return 0;
}